import javassist.ClassPool;
import javassist.NotFoundException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.ParseException;

import java.io.File;

public class Options {
    public String getSrcFileName() {
        return srcFileName;
    }

    public String getSrcDir() {
        return srcDir;
    }

    public String getDestFileName() {
        return destFileName;
    }

    public String getDestDir() {
        return destDir;
    }

    public ClassPool getClassPool() {
        return classPool;
    }

    private String srcFileName;
    private String srcDir;
    private String destFileName;
    private String destDir;
    private ClassPool classPool;

    public static Options createOptions(String[] args) throws NotFoundException {
        Options options = new Options();

        org.apache.commons.cli.Options gnuOptions = new org.apache.commons.cli.Options();
        gnuOptions.addOption("o", "output", true, "output file");

        GnuParser parser = new GnuParser();

        CommandLine cmdLine;
        try {
            cmdLine = parser.parse(gnuOptions, args);
        } catch (ParseException e) {
            throw new IllegalArgumentException("Can not parse args.", e);
        }
        options.srcFileName = cmdLine.getArgs()[0];
        options.destFileName = cmdLine.getOptionValue("o");

        File file = new File(options.srcFileName);
        options.srcDir = file.getParent();

        file = new File(options.destFileName);
        options.destDir = file.getParent();


        options.classPool = ClassPool.getDefault();
        for (String str : System.getProperty("java.library.path").split(":")) {
            options.classPool.appendClassPath(str);
        }
        options.classPool.appendClassPath(options.getSrcDir());


        return options;
    }
}
